﻿<UserControl x:Class="UnitDriven.TestEngine"
			 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
			 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
			 xmlns:e="clr-namespace:UnitDriven.Controls">
	<UserControl.Resources> 
		
		<e:TestStatusConverter x:Key="statusConverter" />
		<e:VisibilityConverter x:Key="visibilityConverter" />

		<DataTemplate x:Key="method">
			<Grid HorizontalAlignment="Stretch" Visibility="{Binding IsVisible}">
				<Border BorderThickness="0,0,0,1" Margin="5,2,5,5" CornerRadius="0,0,0,10" >
					<Border.BorderBrush>
						<LinearGradientBrush EndPoint="0.5,1" StartPoint="0,1">
							<GradientStop Color="#FF000000"/>
							<GradientStop Color="#00FFFFFF" Offset="1"/>
						</LinearGradientBrush>
					</Border.BorderBrush>

					<StackPanel Orientation="Horizontal">
						<Button Margin="4,4,0,4" Content="Run" x:Name="RunMethod" Click="Run_Click" IsEnabled="{Binding IsNotRunning}"/>
						<Ellipse Height="17" Width="17" HorizontalAlignment="Left" Fill="{Binding Status, Converter={StaticResource statusConverter}}" Stroke="#FF000000" Margin="10,0,0,0"/>
						<TextBlock Text="{Binding Name}" Margin="10,0,0,0" VerticalAlignment="Center"/>
						<TextBlock FontWeight="Bold" FontSize="14" Text="{Binding Message}" Margin="10,0,0,0" VerticalAlignment="Center"/>
					</StackPanel>
				</Border>
			</Grid>
		</DataTemplate>

		<DataTemplate x:Key="type">
			<Border BorderBrush="#FF000000" BorderThickness="1,0,0,0" Margin="10,2,10,5" CornerRadius="10,0,0,10" Visibility="{Binding IsVisible}">
				<StackPanel Orientation="Vertical" Margin="10,0,0,0">
					<StackPanel Orientation="Horizontal">
						<ToggleButton Content=" + " IsChecked="{Binding IsExpanded, Mode=TwoWay}" Margin="0,0,5,0" />
						<Button Content="Run" x:Name="RunType" Click="Run_Click" IsEnabled="{Binding IsNotRunning}" />
						<Ellipse Height="17" Width="17" HorizontalAlignment="Left" Fill="{Binding Status, Converter={StaticResource statusConverter}}" Stroke="#FF000000" Margin="10,0,0,0"/>
						<TextBlock Margin="4,4,0,0" VerticalAlignment="Center" Text="Type:"/>
						<TextBlock Margin="4,4,0,0" VerticalAlignment="Center" FontWeight="Bold" Text="{Binding Name}">
							<TextBlock.RenderTransform>
								<TransformGroup>
									<ScaleTransform ScaleX="1.2"/>
								</TransformGroup>
							</TextBlock.RenderTransform>
						</TextBlock>
					</StackPanel>
					<Border x:Name="items" Visibility="{Binding IsExpanded, Converter={StaticResource visibilityConverter}}">
						<ItemsControl Margin="20,0,0,0" ItemTemplate="{StaticResource method}" ItemsSource="{Binding Items}" HorizontalContentAlignment="Stretch" />
					</Border>
				</StackPanel>
			</Border>
		</DataTemplate>
		
		<DataTemplate x:Key="group">
			<Border BorderBrush="#FF000000" BorderThickness="1,0,0,0" Margin="10,2,10,5" CornerRadius="10,0,0,10" >
				<StackPanel Orientation="Vertical" Margin="10,0,0,0">
					<StackPanel Orientation="Horizontal">
						<ToggleButton Content=" + " IsChecked="{Binding IsExpanded, Mode=TwoWay}" Margin="0,0,5,0" />
						<Button Content="Run" x:Name="RunType" Click="Run_Click" IsEnabled="{Binding IsNotRunning}" />
						<Ellipse Height="17" Width="17" HorizontalAlignment="Left" Fill="{Binding Status, Converter={StaticResource statusConverter}}" Stroke="#FF000000" Margin="10,0,0,0"/>
						<TextBlock Margin="4,4,0,0" VerticalAlignment="Center" FontWeight="Bold" Text="{Binding Name}">
							<TextBlock.RenderTransform>
								<TransformGroup>
									<ScaleTransform ScaleX="1.2"/>
								</TransformGroup>
							</TextBlock.RenderTransform>
						</TextBlock>
					</StackPanel>
					<Border x:Name="items" Visibility="{Binding IsExpanded, Converter={StaticResource visibilityConverter}}">
						<ItemsControl Margin="20,0,0,0" ItemTemplate="{StaticResource type}" ItemsSource="{Binding Items}" HorizontalContentAlignment="Stretch" />
					</Border>
				</StackPanel>
			</Border>
		</DataTemplate>
	</UserControl.Resources>

	<Grid x:Name="LayoutRoot" Background="White">
		<Grid.RowDefinitions>
			<RowDefinition Height="40"/>
			<RowDefinition Height="*"/>
		</Grid.RowDefinitions>
		
		<StackPanel Grid.Row="0" Orientation="Horizontal">
			<Button Content="Run All Class Tests" Margin="5,5,5,5" VerticalAlignment="Center" Click="RunAll_Click" IsEnabled="{Binding IsNotRunning}" />
			<TextBlock Text="CSLA Test Engine:" VerticalAlignment="Center"/>
			<TextBlock Text="{Binding Succeeded}" Margin="5,0,0,0" VerticalAlignment="Center"/>
			<TextBlock Text="/" Margin="3,0,3,0" VerticalAlignment="Center"/>
			<TextBlock Text="{Binding Total}" VerticalAlignment="Center"/>
			<TextBox 
				x:Name="filterText"
				Text="{Binding Filter, Mode=TwoWay}" 
				Width="200" 
				Margin="5,10,5,5" 
				VerticalContentAlignment="Center"
				TextInput="TextBox_TextInput"
				GotFocus="TextBox_GotFocus" />
			<Button 
				Content="Errors"
				Margin="10,0,0,0"
				VerticalAlignment="Center"
				Visibility="{Binding HasError, Converter={StaticResource visibilityConverter}}"
				Click="ErrorDetails_Click" />
			<Button
				Click="SummaryCopy_Click"
				Margin="10,0,0,0"
				VerticalAlignment="Center"
				Content="Summary" />
		</StackPanel>
		
		<ScrollViewer Margin="0,5,0,0" Grid.Row="1">
			<ItemsControl Margin="0,5,0,0" x:Name="types" ItemTemplate="{StaticResource group}" ItemsSource="{Binding Items}" HorizontalContentAlignment="Stretch" />
		</ScrollViewer>
	</Grid>
</UserControl>
